﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Dcms.BLL;
using Dcms.Model;
using Dcms.Common;
using AjaxPro;

public partial class Manage_Modle_CateGory_OperateCate : System.Web.UI.Page
{
    private string strCatID
    {
        get
        {
            return Request.QueryString["CatID"] + "";
        }
    }
    private string strAction
    {
        get
        {
            return Request.QueryString["action"] + "";
        }
    }

    #region 页面加载
    protected void Page_Load(object sender, EventArgs e)
    {
        CompetenceLib CL = new CompetenceLib();
        CL.IsLogin();
        Utility.RegisterTypeForAjax(typeof(Dcms.BLL.Dcms_CateBLL));
        try
        {
            if (!IsPostBack)
            {
                string Language = "";
                if (Session["DCMSLANGUAGE"] != null)
                {
                    Language = Session["DCMSLANGUAGE"].ToString();
                }

                lab_Title.Text = "（请从左边选您所要操作的栏目或分类）";
                if (Request.QueryString["CatID"] != null)
                {
                    Dcms_CateBLL cBll = new Dcms_CateBLL();
                    Dcms_CateModel cModel = new Dcms_CateModel();
                    cModel = cBll.GetModelByID(Convert.ToInt32(strCatID));

                    if (strAction == "move")
                    {
                        lab_Title.Text = "（移动“" + cModel.Cate_Name + "”类别下的所有数据到另一类别下）";
                        btnOk.Text = "移动";
                    }
                    else if (strAction == "copy")
                    {
                        lab_Title.Text = "（复制“" + cModel.Cate_Name + "”类别下的所有数据到另一类别下）";
                        btnOk.Text = "复制";
                    }
                }

                //取得所有语言版本
                string strLanguage = ConfigurationManager.AppSettings["Language"];
                string strLanguageNmae = ConfigurationManager.AppSettings["LanguageNmae"];
                string[] arrLanguage = strLanguage.Split(',');
                string[] arrLanguageNmae = strLanguageNmae.Split(',');
                for (int i = 0; i < arrLanguage.Length; i++)
                {
                    ddlLanguage.Items.Add(new ListItem(arrLanguageNmae[i], arrLanguage[i]));
                }
                ddlLanguage.SelectedValue = Language;
                ChangeLanguage();
            }
        }
        catch (Exception ex)
        {
            Log.LogHandler.LogError("Manage_Modle_CateGory_OperateCate.Page_Load", ex);
            throw ex;
        }
    }
    #endregion

    #region 确定
    protected void btnOk_Click(object sender, EventArgs e)
    {
        if (hid_CateID.Value == "")
        {
            RegisterStartupScript(this.ToString(), "<script>alert('目标分类为空!');</script>");
            return;
        }
        Dcms_CateBLL cBll = new Dcms_CateBLL();
        Dcms_CateModel cModel = cBll.GetModelByID(Convert.ToInt32(strCatID));
        if (strAction == "move")
        {
            switch(cModel.Cate_Flag.ToLower().Trim())
            {
                case "product":
                    Dcms_ProductsBLL pBll = new Dcms_ProductsBLL();
                    pBll.MoveProducts(Convert.ToInt32(strCatID), Convert.ToInt32(hid_CateID.Value));
                    break;
                case "news":
                    Dcms_NewsBLL nBll = new Dcms_NewsBLL();
                    nBll.MoveNews(Convert.ToInt32(strCatID), Convert.ToInt32(hid_CateID.Value));
                    break;
                case "intor":
                    Dcms_IntroBLL iBll = new Dcms_IntroBLL();
                    iBll.MoveIntro(Convert.ToInt32(strCatID), Convert.ToInt32(hid_CateID.Value));
                    break;
                case "link":
                    Dcms_LinkBLL lBll = new Dcms_LinkBLL();
                    lBll.MoveLink(Convert.ToInt32(strCatID), Convert.ToInt32(hid_CateID.Value));
                    break;
                case "down":
                    Dcms_DownBLL dBll = new Dcms_DownBLL();
                    dBll.MoveDown(Convert.ToInt32(strCatID), Convert.ToInt32(hid_CateID.Value));
                    break;
                default:
                    RegisterStartupScript(this.ToString(), "<script>alert('不存在您要操作的模块!');</script>");
                    break;
            }
        }
        else if (strAction == "copy")
        {
            switch (cModel.Cate_Flag.ToLower().Trim())
            {
                case "product":
                    Dcms_ProductsBLL pBll = new Dcms_ProductsBLL();
                    pBll.CopyProducts(Convert.ToInt32(strCatID), Convert.ToInt32(hid_CateID.Value));
                    break;
                case "news":
                    Dcms_NewsBLL nBll = new Dcms_NewsBLL();
                    nBll.CopyNews(Convert.ToInt32(strCatID), Convert.ToInt32(hid_CateID.Value));
                    break;
                case "intor":
                    Dcms_IntroBLL iBll = new Dcms_IntroBLL();
                    iBll.CopyIntro(Convert.ToInt32(strCatID), Convert.ToInt32(hid_CateID.Value));
                    break;
                case "link":
                    Dcms_LinkBLL lBll = new Dcms_LinkBLL();
                    lBll.CopyLink(Convert.ToInt32(strCatID), Convert.ToInt32(hid_CateID.Value));
                    break;
                case "down":
                    Dcms_DownBLL dBll = new Dcms_DownBLL();
                    dBll.CopyDown(Convert.ToInt32(strCatID), Convert.ToInt32(hid_CateID.Value));
                    break;
                default:
                    RegisterStartupScript(this.ToString(), "<script>alert('不存在您要操作的模块!');</script>");
                    break;
            }
        }
    }
    #endregion

    /// <summary>
    /// 选择语言版本,加载分类
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void ddlLanguage_SelectedIndexChanged(object sender, EventArgs e)
    {
        ChangeLanguage();
    }

    private void ChangeLanguage()
    {
        Dcms_CateBLL cBll = new Dcms_CateBLL();
        Dcms_CateModel cModel = new Dcms_CateModel();
        cModel = cBll.GetModelByID(Convert.ToInt32(strCatID));

        Dcms_CateModel cParentModel = cBll.GetModelByFlag(cModel.Cate_Flag, cModel.Cate_ModelKeyId, ddlLanguage.SelectedValue);
        hid_Language.Value = ddlLanguage.SelectedValue;
        hid_CateID.Value = "";
        hid_ParentID.Value = cParentModel.Cate_ID.ToString();
        txb_CateName.Text = "";
    }
}
